//
//  FANSearchView.m
//  Weibo - OC
//
//  Created by user on 16/4/16.
//  Copyright © 2016年 user. All rights reserved.
//

#import "FANSearchView.h"

@interface FANSearchView ()

@property (weak, nonatomic) IBOutlet UITextField *textField;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rightCons;

@property (nonatomic, strong) UIImageView *searchImageView;

@end

@implementation FANSearchView

- (UIImageView *)searchImageView{
    
    if (_searchImageView == nil) {
        
        _searchImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"searchbar_textfield_search_icon"]];
        
        _searchImageView.frame = CGRectMake(0, 0, self.textField.frame.size.height/1.5, self.textField.frame.size.height/2);
        
        _searchImageView.contentMode = UIViewContentModeCenter;
        
    }
    
    return _searchImageView;
}

+(instancetype)loadSearchView{
    
    return [[[NSBundle mainBundle] loadNibNamed:@"FANSearchView" owner:nil options:nil] lastObject];
}

- (void)awakeFromNib{
    
    
    
    self.textField.leftView = self.searchImageView;
    
    self.textField.leftViewMode = UITextFieldViewModeAlways;
}

- (void)layoutSubviews{
    
    [super layoutSubviews];

    self.textField.layer.cornerRadius = 5;
    
    self.textField.layer.masksToBounds = YES;
    
    self.textField.layer.borderColor = [UIColor orangeColor].CGColor;
    
    self.textField.layer.borderWidth = 2;
}

- (IBAction)editingBegin:(UITextField *)sender {
    
 

    self.rightCons.constant = 45;
    
    [UIView animateWithDuration:0.25 animations:^{
        
        [self layoutIfNeeded];
        
    }];
}


- (IBAction)didClickCancel:(UIButton *)sender {
    
    self.rightCons.constant = 0;
    
    [UIView animateWithDuration:0.25 animations:^{
        
        [self layoutIfNeeded];
        
    }];
    
    [self.textField resignFirstResponder];
    
}



@end
